import backEnd.utils
import backEnd.database.DBOperation as DBOperation
import pandas as pd


def insert_admin():
    # 使用示例
    admin_list = []
    for _ in range(1):
        data = {
            'id': backEnd.utils.generate_id(),
            'name': backEnd.utils.generate_random_name(),
            'password': backEnd.utils.generate_id(6),
            'permission': 1
        }
        admin_list.append(data)
    df = pd.DataFrame(admin_list, range(1))
    print(df)
    db = DBOperation.db_Operation()
    db.insert("administrator", df)


def create_user(num):
    user_list = []
    for i in range(num):
        item = {
            'id': i,
            'address': '华南理工大学',
            'birthday': '2002-12-11',
            'identity_id': 441502200311220100 + i,
            'name': backEnd.utils.generate_random_name(),
            'password': '123456',
            'remaining': 100,
            'telephone': '18927960048'
        }
        user_list.append(item)
    return pd.DataFrame(user_list)


def create_history(num):
    history_list = []
    for i in range(num):
        item = {
            'id': i,
            'id_operator': 1,
            'name_operator': 'roson',
            'date': '2023-5-22',
            'type': 1,
            'pass': 1,
        }
        history_list.append(item)
    return pd.DataFrame(history_list)


def insert(table_name, data):
    db = DBOperation.db_Operation()
    work, result = db.insert(table_name, data)
    db.close()
    return work, result


if __name__ == '__main__':
    # insert('history', create_history(50))
    pass